/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package pro.dao;

 
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ArrayList;
import pro.bean.*;
import java.sql.DriverManager;
import java.sql.PreparedStatement;


/**
 *
 * @author Cyndi
 */
public class RolDAO extends Dbase{
    
    
    public ArrayList<Rol> listarRoles() throws SQLException {
         this.init_mysql();
        PreparedStatement pstmt = null;
        ResultSet rs = null;

        
        ArrayList<Rol> listaRoles = new ArrayList<Rol>();
        
        try {
            
            pstmt =  conn.prepareStatement("SELECT idroles,nombre FROM roles" );
                     
            rs = pstmt.executeQuery();
            Rol nuevoRol = null;
            while (rs.next()) {
                nuevoRol = new Rol();
                nuevoRol.setIdRol(rs.getInt(1));
                nuevoRol.setNombre(rs.getString("nombre"));
                listaRoles.add(nuevoRol);
            }
        }    finally {
            if (rs != null) {rs.close(); rs = null; }
            if (pstmt != null) {pstmt.close();pstmt = null; }
            if (conn != null) {conn.close();conn = null;}
        }
        return listaRoles;
    }
}
    
    


    
    
    
    

